package ar.edu.unq.tpi.pconc.tpconcurbattle.utils;

import ar.edu.unq.tpi.pconc.Channel;

public class ServerChannel {
	
	private static ServerChannel instance;
	
	private int currentChannelId;
	
	private ServerChannel() {
		super();
		this.currentChannelId = Util.PRIMER_INT_CANAL;
	}
	
	public static ServerChannel getInstance() {
		if(ServerChannel.instance == null) {
			ServerChannel.instance = new ServerChannel();
		}
		return ServerChannel.instance;
	}
	
	public int getNextChannelId() {
		return this.currentChannelId++;
	}
	
	public static void main(String[] args) {
		int n = Util.PRIMER_INT_CANAL;
		
		Channel<String> cConsulta = new Channel<String>(Util.SERVER_CHANNEL_RECIEVE);
		Channel<Integer> cRespuesta = new Channel<Integer>(Util.SERVER_CHANNEL_SEND);
		
		while (true) {
			String consulta = cConsulta.receive();
			if("new".equalsIgnoreCase(consulta)) {
				System.out.println("pedido new");
				cRespuesta.send(n);
				//System.out.println("Incrementando n");
				n++;
				System.out.println("n incrementado a " + n);
			}
		}
	}

}
